package com.totoro.mapper;

import com.totoro.pojo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author TOTORO
 * @date 2021/7/7 18:25
 */
@Repository
public interface ProductMapper {

    Integer addProduct(Product product);

    Integer addProductSkus(ProductSpecs productSpecs);

    Integer addProductImages(ProductImage productImage);

    Integer updateProductStock(@Param("type") int type, @Param("count") int count, @Param("pid") int pid);

    Integer updateSkuGroupStock(@Param("type") int type, @Param("count") int count, @Param("psId") int psId);

    Product findProductById(@Param("pid") int pid);

    Integer[] findAllProductId();

    Integer findMinSkuIdByPid(@Param("pid") int pid);

    Integer findMaxSkuIdByPid(@Param("pid") int pid);

    List<ProductSpecs> findProductSkusById(@Param("pid") int pid);

    ProductSpecs findAssignSkuByPidAndSkuId(@Param("skuId") int skuId);

    List<ProductSpecs> findAssignSkusByPidAndSkuData(@Param("pid") int pid, @Param("skuData") String skuData);

    List<ProductImage> findProductImagesById(@Param("pid") int pid);

    List<Product> findProductsByName(@Param("productName") String productName, @Param("sort") String sort, @Param("isDiscount") boolean isDiscount, @Param("curr") int curr,
                                     @Param("lowPrice") double lowPrice, @Param("highPrice") double highPrice, @Param("belongCategoryId") int belongCategoryId);

    Integer addProductComment(ProductComment productComment);

    Integer addProductCommentImage(CommentImage commentImage);

    Integer addProductAppendComment(AppendComment appendComment);

    Integer addProductAppendCommentImage(CommentImage commentImage);

    List<ProductComment> findProductAllEvaluationByPid(@Param("pid") int pid, @Param("type") int type, @Param("sort") String sort);

    ProductComment findProductEvaluationByMsId(@Param("msId") int msId);

    List<ProductComment> findUserAllEvaluationBySlid(SuperEvaluationFind superEvaluationFind);

    List<ProductComment> findUserMultipleEvaluation(@Param("findType") int findType, @Param("id") Object id, @Param("showType") int showType, @Param("showContent") int showContent);

    ProductComment findOneEvaluation(@Param("pcId") int pcId);

    List<CollectProduct> findAllUserCollectProduct(@Param("uid") int uid, @Param("value") String value);

    CollectProduct checkUserCollectProduct(@Param("uid") int uid, @Param("pid") int pid);

    Integer collectProduct(@Param("uid") int uid, @Param("pid") int pid);

    Integer cancelCollectProduct(@Param("uid") int uid, @Param("pid") int pid);

    Integer batchDeleteCollectProduct(@Param("collectIds") Integer[] collectIds);

    Integer updateProductCollectCount(@Param("type") int type, @Param("pid") int pid);

    Integer batchReduceProductCollectCount(@Param("collectIds") Integer[] collectIds);

    Integer addBuyShop(BuyShop buyShop);

    BuyShop checkUserBuyShop(BuyShop buyShop);

    List<BuyShop> findAllUserBuyShop(@Param("uid") int uid, @Param("categoryId") int categoryId, @Param("keyword") String keyword, @Param("curr") int curr);

    Integer deleteBuyShop(@Param("uid") int uid, @Param("sid") int sid);

    Integer addProductCommentCount(@Param("pid") int pid);

    Integer addSellerReply(SellerReply sellerReply);

    Integer updateIsReply(@Param("pcId") int pcId);

    Integer findCategoryIdByPid(@Param("pid") int pid);

    Integer deleteEvaluationImage(@Param("ciId") int ciId);

    Integer deleteAppendEvaImage(@Param("aciId") int aciId);

    Integer updateEvaluationAnonymous(@Param("pcId") int pcId);

    Integer updateEvaluationIsHaveImage(@Param("pcId") int pcId, @Param("status") int status);

    Integer updateAppendEvaIsHaveImage(@Param("acId") int acId, @Param("status") int status);

    Integer updateProductPriceAndStockByPid(Product product);

    Integer updateProductStatusByPid(@Param("pid") int pid, @Param("isUpdate") boolean isUpdate, @Param("status") int status, @Param("isDelete") boolean isDelete, @Param("deleteStatus") int deleteStatus);

    Integer updateProductName(@Param("productId") int productId, @Param("productName") String productName, @Param("itMethod") int itMethod);

    Integer updateProductDeleteTime(@Param("pid") int pid);

    Integer addProductRecover(@Param("reasonId") int reasonId, @Param("pid") int pid);

    List<SearchTextList> findSearchText(@Param("texts") String[] texts);

    List<SearchTextList> findReturn(@Param("value") String value);

    Integer addProductMonthDeal(@Param("integers") Integer[] integers);

    Integer updateProductMonthDeal(ProductMonthDeal productMonthDeal);

    ProductMonthDeal findNowMonthIsHaveProductDeal(ProductMonthDeal productMonthDeal);

    Integer[] findRecentRandHistoryProducts(@Param("uid") int uid);

    Integer[] findHotRandHistoryProducts();

    Integer[] findKeywordAgoProducts();

    List<Product> recommendPidFind(@Param("productIds") Integer[] productIds);

    List<Product> fuzzyFindProduct(@Param("keywords") List<String> keywords, @Param("productCount") int productCount);

    Integer[] getRandShopProduct(@Param("sid") int sid, @Param("notPid") int notPid, @Param("limitCount") int limitCount);

    List<Product> findShopOtherProducts(@Param("sid") int sid, @Param("notPid") int notPid, @Param("limitCount") int limitCount);


    /**
     * 修改产品点击次数
     * @param pid
     * @return
     */
    @Update("update product set click_count=click_count+1 where product_id=#{pid}")
    Integer updateProductClickCount(@Param("pid") int pid);

    /**
     * 修改类别点击次数
     * @param cid
     * @return
     */
    @Update("update category set click_count=click_count+1 where cid=#{cid}")
    Integer updateCategoryClickCount(@Param("cid") int cid);

    /**
     * 修改产品成交次数（购买次数）
     * @param pid
     * @return
     */
    @Update("update product set deal_count = deal_count+1 where product_id=#{pid}")
    Integer updateProductDealCountByPid(@Param("pid") int pid);
}
